Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
Turn string[][] into a string[]

I'm filtering data from 2 objects that I receive from an API. I need to have a ['data', 'data2', 'dat2'], but when I get the data I'm receiving like this:

[ ['data'], ['data2', 'dat3'] ] 

I need to transform that into:

['data', 'data2', 'dat2']

This is how I'm filtering the data:

    const filteredData = response.data.map((value) => {
      const data = value.students.map((value) => {
        return value.studentId;
      });

      return filteredData;
    });

If you are wondering how is the data set:
Data:

[
  {
    id: 1,
    students: [
     {id: 1, studentId: 1829},
     {id: 2, studentId: 4329}
    ]
  },
  {
    id: 2,
    students: [
     {id: 3, studentId: 1429},
     {id: 6, studentId: 329}
    ]
  }
]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use flat to flatten nested arrays

[ ['data'], ['data2', 'dat3'] ].flat()

And flatMap(x => x.students) to flatten arrays within more complex object structures

const data = [
  {
    id: 1,
    students: [
     {id: 1, studentId: 1829},
     {id: 2, studentId: 4329}
    ]
  },
  {
    id: 2,
    students: [
     {id: 3, studentId: 1429},
     {id: 6, studentId: 329}
    ]
  }
]

const flattened = data.flatMap(x => x.students)

// Output:
[
    {
        "id": 1,
        "studentId": 1829
    },
    {
        "id": 2,
        "studentId": 4329
    },
    {
        "id": 3,
        "studentId": 1429
    },
    {
        "id": 6,
        "studentId": 329
    }
]
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!